<template>
    <div class="app-container">

        <el-form :model="params" ref="queryForm" size="small" :inline="true" label-width="120px">
            <el-form-item label="班级" prop="classId">
                <el-select clearable v-model="params.classId">
                    <el-option v-for="(v, i) in class_list" :key="i" :label="v.className"
                        :value="v.classId"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="年级" prop="gradeId">
                <el-select v-model="params.gradeId" placeholder="请选择年级" filterable clearable>
                    <el-option v-for="(v, i) in gradeList" :key="i" :label="v.gradeName" :value="v.gradeId">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="params.stuName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="学号" prop="stuNo">
                <el-input v-model="params.stuNo" placeholder="请输入学号" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                <!-- <el-button icon="el-icon-upload2" size="mini" @click="confirmVClick">费用记录发起确认</el-button> -->
            </el-form-item>
        </el-form>


        <el-table v-loading="loading" :data="tableData">
            <el-table-column label="学号" align="center" prop="stuNo" />
            <el-table-column label="班级" align="center" prop="className" />
            <el-table-column label="姓名" align="center" prop="stuName" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookLog(scope.row)">
                        <span>查看住宿记录</span>
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookTask(scope.row)">
                        <span>查看学生调宿计划</span>
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="params.pageNum" :limit.sync="params.pageSize"
            @pagination="getList" />

        <el-dialog :visible.sync="logV" title="住宿记录" width="90%">
            <h2>当前宿舍:{{ now_dorm }}</h2>
            <el-table :data="log_list">
                <el-table-column label="学号" align="center" prop="stuNo" />
                <el-table-column label="姓名" align="center" prop="stuName" />
                <el-table-column label="宿舍" align="center" prop="roomId" width="200">
                    <template slot-scope="scope">
                        <span>{{ scope.row.campusName + " " + scope.row.parkName + " " + scope.row.buildingName + " " +
                            scope.row.floorName + "层" + scope.row.roomNo }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="开始日期" align="center" prop="startDate" />
                <el-table-column label="结束日期" align="center" prop="endDate" />
                <el-table-column label="折合月数" align="center" prop="inMonth" />
                <el-table-column label="收费标准/10个月" align="center" prop="mainMoney" />
                <el-table-column label="应收费用" align="center" prop="needMoney" />
                <el-table-column label="农行卡号" align="center" prop="bankCard" />
                <el-table-column label="区间" align="center" prop="rangeName" />
                <el-table-column label="费用状态" align="center" prop="applyStatus">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.dms_record_status" :value="scope.row.applyStatus" />
                    </template>
                </el-table-column>
                <!-- <el-table-column label="操作" align="center" prop="applyStatus">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.applyStatus == '6'" size="mini" type="text" icon="el-icon-upload2"
                            @click="oneConfirm(scope.row)">
                            <span>发起确认</span>
                        </el-button>
                    </template>
                </el-table-column> -->
            </el-table>
        </el-dialog>

        <el-dialog :visible.sync="taskV" title="查看学生调宿计划" width="90%">
            <el-table :data="task_list">
                <el-table-column label="学号" align="center" prop="stuNo" width="100" />
                <el-table-column label="姓名" align="center" prop="stuName" />
                <el-table-column label="旧宿舍" align="center" prop="oldDorm" width="200" />
                <el-table-column label="新宿舍" align="center" prop="newDorm" width="200" />
                <el-table-column label="任务类型" align="center" prop="taskType">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.dms_change_status" :value="scope.row.taskType" />
                    </template>
                </el-table-column>
                <el-table-column label="任务预执行日期" align="center" prop="taskWant" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.taskWant, '{y}-{m}-{d}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="任务执行时间" align="center" prop="taskRun" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.taskRun) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="任务执行状态" align="center" prop="taskStatus">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.dms_task_status" :value="scope.row.taskStatus" />
                    </template>
                </el-table-column>

            </el-table>
        </el-dialog>

        <el-dialog title="费用记录发起确认" :visible.sync="confirmV">
            <el-form>
                <el-form-item label="班级" label-width="40px">
                    <el-select style="width: 100%;" size="mini" v-model="confirmForm.classId">
                        <el-option v-for="(v, i) in class_list" :key="i" :label="v.className"
                            :value="v.classId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="学年" label-width="40px">
                    <el-select style="width: 100%;" size="mini" v-model="confirmForm.stuYearId">
                        <el-option v-for="(v, i) in year_list" :key="i" :label="v.stuYearName"
                            :value="v.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label-width="40px">
                    <el-button @click="sendConfirm" size="mini">发起确认</el-button>
                </el-form-item>

            </el-form>
        </el-dialog>


    </div>
</template>
<script>
import { listFdy, getStuLog } from "@/api/dormitory/new/stuDom";
import { sendConfirm, oneConfirm } from "@/api/dormitory/new/record";

import { fullLoading } from "@/api/helpFunc";

import { listStuTask } from "@/api/dormitory/new/task";
import { listOwnClass } from "@/api/stuCQS/info-fill/stu_eva_task";
import { listAllYear } from "@/api/stuCQS/basedata/year";
import { listGrade } from "@/api/stuCQS/basedata/grade";

export default {
    name: "stuDom_fdy",
    dicts: ['dms_approval_status', 'dms_task_status', 'dms_change_status', 'dms_record_status'],
    data() {
        return {
            loading: false,
            params: {
                pageSize: 10,
                pageNum: 1,
                stuNo: null
            },
            tableData: [],
            total: 0,
            logV: false,
            log_list: [],
            now_dorm: "暂无",

            taskV: false,
            task_list: [],

            confirmV: false,
            class_list: [],
            year_list: [],

            confirmForm: {
                classId: null,
                stuYearId: null
            },
            gradeList: [],//年级列表
        }
    },
    created() {
        this.listGrade();
        this.listAllYear();
        this.listOwnClass();
        this.getList();
    },
    methods: {
        async listGrade() {
            let res = await listGrade();
            this.gradeList = [...res.rows];
        },
        async oneConfirm(val) {
            let id = val.id;
            let loading = fullLoading(this);
            let res = await oneConfirm(id);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.lookLog(val);
            }
        },
        async sendConfirm() {
            let sdata = { ...this.confirmForm };
            let loading = fullLoading(this);
            let res = await sendConfirm(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
            }
        },
        async listAllYear() {
            let res = await listAllYear();
            if (res.code == 200) {
                this.year_list = [...res.data];
            }
        },
        async listOwnClass() {
            this.loading = true;
            let res = await listOwnClass();
            this.loading = false;
            if (res.code == 200) {
                this.class_list = [...res.data];
            }
        },
        confirmVClick() {
            this.confirmV = true;
        },
        async lookTask(row) {
            let stuNo = row.stuNo;
            let loading = fullLoading(this);
            let res = await listStuTask(stuNo);
            loading.close();
            if (res.code == 200) {
                this.task_list = [...res.data];
                this.taskV = true;
            }
        },

        async lookLog(row) {
            this.now_dorm = "暂无";
            let stuNo = row.stuNo;
            let loading = fullLoading(this);
            let res = await getStuLog(stuNo);
            loading.close();
            if (res.code == 200) {
                console.log(res);
                let data = { ...res.data };
                let temp = [...data.record];

                let i = 0;
                temp.map(x => {
                    if (x.startDate == "1970-01-01") {
                        x.startDate = "学期开始";
                    }
                    if (x.endDate == "1970-01-01") {
                        x.endDate = "学期结束";
                    }
                    i++;
                });
                this.log_list = [...temp];
                if (data.dormStu != null) {
                    let temp = { ...data.dormStu };
                    this.now_dorm = temp.campusName + " " + temp.parkName + " " + temp.buildingName + " " + temp.floorName + "层" + temp.roomNo;
                }
                this.logV = true;
            }
        },
        async getList() {
            this.loading = true;
            let res = await listFdy(this.params);
            this.loading = false;
            if (res.code == 200) {
                this.total = res.total;
                this.tableData = [...res.rows];
            }
        },
        handleQuery() {
            this.params.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
    }
}


</script>